<?php
session_start();
// Connect to the DB.
$_SESSION["errmsg"] = '';
require_once '../include/config.lib.php';
require_once '../include/database.lib.php';
require_once '../include/PHPMailer/class.phpmailer.php';

ConnectToDB();


	$mail             = new PHPMailer();
	//$body             = file_get_contents('contents.html');
	//$body             = eregi_replace("[\]",'',$body);
	$body             = "<b>The user: </b>".$_POST["userName"]." (user ID '". $_POST["userID"] ."') has been reported for abusive behavior.<br><br>"
						."<b>Abusive event: </b>" . $_POST["event"] . "<br><br>"
						. "<b>Reason the event was considered offensive: </b>" . $_POST["reason"] .  "<br><br>"
						. "<b>Reported by: </b>".$_SESSION["accountNo"]." (user ID '". $_SESSION["personid"] ."')";
	
	print($body);

	$mail->IsSMTP(); // telling the class to use SMTP
	//$mail->Host       = "mail.yourdomain.com"; // SMTP server
	$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
	                                           // 1 = errors and messages
	                                           // 2 = messages only
	$mail->SMTPAuth   = true;                  // enable SMTP authentication
	$mail->SMTPSecure = "tls";                 // sets the prefix to the servier
	$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
	$mail->Port       = 587;                   // set the SMTP port for the GMAIL server
	$mail->Username   = "coraladmn@gmail.com";  // GMAIL username
	$mail->Password   = "fab4coral";            // GMAIL password
	
	$mail->SetFrom('coraladmn@gmail.com', 'CoRAL');
	
	//$mail->AddReplyTo("dialy.cs@gmail.com","First Last");
	
	$mail->Subject    = "CoRAL: User reported for abuse";
	
//	$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
	
	$mail->MsgHTML($body);
	
	$address = "coraladmn@gmail.com";	//replace with an administrators email
	$mail->AddAddress($address, "CoRAL Administrator");
	
	if(!$mail->Send()) {
//	  echo "Mailer Error: " . $mail->ErrorInfo;
	$_SESSION["errmsg"] = 'Sorry, Internal Error!';
	} else {
//	  echo "Message sent!";
	$_SESSION["errmsg"] = 'Your abuse report has been sent to an administrator';
	}
	
	$url = "../person_view.php?id=". $_POST["userID"];
	echo "<HTML><META http-equiv=\"refresh\" content=\"0; url='".$url."'\"></HTML>";//redirect to the previous page
?>